/* 试卷息管理 */
import React, { Component } from 'react'
import { Tabs, Card } from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import { history } from 'umi'
import { SwapOutlined, UserSwitchOutlined, FileTextOutlined, BlockOutlined, ExportOutlined } from '@ant-design/icons';
import Random from './Random'
import Manual from './Manual'
import Management from './Management'
import ParamTemplate from './ParamTemplate'
import PersonTemplate from './PersonTemplate'
import Authorized from '../../components/Authorized/Authorized'
export default class Index extends Component<any, any> {
    constructor(props: any) {
        super(props);
        this.state = {
            currentTab: window.location.hash[window.location.hash.length - 1],
            subjectData: [],
            subjectDataOptions: [],
            subjectTreeSelect: []
        };
    }
    changeTabHandle = (e: string) => {
        this.setState({
            currentTab: e
        })
        if (this.props.location.pathname.indexOf('tzExamInfo') === -1) {
            history.push('/examInfo/testPaper/' + e)
        }else{
            history.push('/tzExamInfo/testPaper/' + e)
        }
    }
    componentDidMount() {
        const currentTab = this.props.match.params.tab === ':tab' ? '3' : this.props.match.params.tab
        this.setState({
            currentTab
        })
    }
    render() {
        const { currentTab } = this.state;
        const renderChild=(currentTab: string)=> {
            switch (currentTab) {
                case '2':
                    return <Authorized authority={[502,99999992]}><Manual changeTabHandle={this.changeTabHandle}/></Authorized>;
                case '3':
                    return<Management />;
                case '4':
                    return <ParamTemplate />;
                case '5':
                    return <Authorized authority={[]}><PersonTemplate /></Authorized>;
                default:
                    return <Authorized authority={[501,99999991]}><Random changeTabHandle={this.changeTabHandle}/></Authorized>;
            }
        }
        return (
            <PageContainer>
                <Card>
                    <Tabs onChange={this.changeTabHandle} activeKey={currentTab}>
                        <Tabs.TabPane key="1" tab={<span><SwapOutlined />随机组卷</span>}></Tabs.TabPane>
                        <Tabs.TabPane key="2" tab={<span><UserSwitchOutlined />人工组卷</span>}></Tabs.TabPane>
                        <Tabs.TabPane key="3" tab={<span><FileTextOutlined />试卷管理</span>}></Tabs.TabPane>
                        <Tabs.TabPane key="4" tab={<span><BlockOutlined />试卷参数模板</span>}></Tabs.TabPane>
                        {/* <Tabs.TabPane key="5" tab={<span><ExportOutlined />人员抽考模板</span>}></Tabs.TabPane> */}
                    </Tabs>
                    {renderChild(currentTab)}
                </Card>
            </PageContainer>
        )
    }
}
